import Raven from 'raven-js'
import CONFIG from "./config"

// Raven.config(CONFIG.raven_config).install()

function addErrorListener() {
    return ()=>{
        window.onerror = (msg,url,line,col,error) => {
            if(msg === "Uncaught ReferenceError: WeixinJSBridge is not defined" ||
               msg === "ReferenceError: Can't find variable: WeixinJSBridge") {
                return
            }
            //没有URL 和 msg 不上报！
            if(msg === "Script error." && !url){
                return 
            }
            setTimeout(function(){
                const data = {
                    msg,
                    url,
                    line,
                    col
                }
                //把data上报到后台！
                // Raven.captureMessage(JSON.stringify(data),{level: 'info'})
            },0)
            return 
        }
    }
}
function reportError(error) {
    // Raven.captureException(error)
}
module.exports = {
    addErrorListener,
    reportError
}